

account_list=[
    {'id': '001', 'cipher': '123456', 'name': '张三', 'money': 1000},
    {'id': '002', 'cipher': '123456', 'name': '李四', 'money': 0},
    {'id': '003', 'cipher': '123456', 'name': '王五', 'money': 5000}
]

user=''
# 登录系统
def join_account():
    global user
    USER=input('请输入你的账户')
    cipher=input('请输入密码')
    for i in range(len(account_list)):
        if account_list[i]['id']==USER and account_list[i]['cipher']==cipher:
                user=USER
                print('登录成功')
                break
        elif input("输入的账号密码有误，是否重新输入 yes/no?  ") == "yes":
                join_account()  # 重新输入


# 查看余额
def show_money():
    for i in range(len(account_list)):
        if account_list[i]['id']==user:
            print('你的账户还有{}元'.format(account_list[i]['money']))


# 存钱
def add_momey():
    try:
        addMoney=int(input('请输入您需要存入的金额'))
    except:
        print('输入错误，重新输入')
        add_momey()
        return

    for i in range(len(account_list)):
        if user==account_list[i]['id']:
            account_list[i]['money']+=addMoney
            print("您成功存款{}元".format(addMoney))
            break



# 取钱
def del_momey():
    try:
        addMoney = int(input('请输入您需要取走的金额'))
    except:
        print('输入错误，重新输入')
        add_momey()
        return

    for i in range(len(account_list)):
        if user == account_list[i]['id']:
            account_list[i]['money'] -= addMoney
            if account_list[i]['money']<0:
                account_list[i]['money'] += addMoney
                print('你的余额不足')
                show_money()
            elif account_list[i]['money']>=0:
                print("您成功取款{}元".format(addMoney))




while True:
    # 输出初始界面
    print('='*12,'自动取款机','='*12)
    print('{:1} {:13} {:15}'.format(' ','1.登录','2.查看余额'))
    print('{:1} {:13} {:15}'.format(' ', '3.存钱', '4.取钱'))
    print('{:1} {:13}'.format(' ', '5.退出'))
    print('=' * 36)
    key=input('请输入对应的选择')
    #根据输入操作值，执行对应操作
    if key=='1':
        join_account()
        input('按回车键继续')

    elif key=='2':

        show_money()
        input('按回车键继续')
    elif key=='3':

        add_momey()
        show_money()
        input('按回车键继续')
    elif key=='4':
        del_momey()
        show_money()

    elif key=='5':

        print('=' * 12, '再见', '=' * 12)
        break

    else:
        print('=' * 12, '输入无效', '=' * 12)
        input('按回车键继续')






